package be.xios.projectquiz.global;

import java.sql.Timestamp;
import java.util.Date;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import be.xios.projectquiz.game.Game;
import be.xios.projectquiz.game.Player;

/// <summary>
/// Deze klasse deelt items tussen de JURYGUI, PLAYER-, MASTER- en hun respectievelijke clients
/// </summary>
/// <author>Sebastian Kubski</author>

public class SharedItems {

		private JMenuItem connect;
		private JLabel  connstatus;	
		private boolean gameChosen; // nog nodig?
		private Game game;
		private Player player; //group extends player en kan dus bijgevolg in player!
		private JFrame originalFrame;
		private Date date;

		public SharedItems(JFrame originalFrame, JLabel connstatus, JMenuItem connect) {
			this.originalFrame=originalFrame;
			this.gameChosen=false;
			this.game=null;
			this.connstatus=connstatus;
			this.connect=connect;
			this.player=null;
			this.date=new Date();
		}
		
		//Getters-setters
		//Game opvragen en setten
		public Game getGame() {
			return game;
		}

		public void setGame(Game game, String client) {
			this.game = game;
			
			if ( client.equals("JURY")) {
				System.out.println("[" + new Timestamp(date.getTime()) + "] CLIENTSIDE: " + Thread.currentThread().getName() + " JURY has chosen " + game.getGameName());
			}
			else {
				System.out.println("[" + new Timestamp(date.getTime()) + "] CLIENTSIDE: " + Thread.currentThread().getName() + " " + client + " has received and set " + game.getGameName());
			}			
		}
		//Controle of een game is geset
		public boolean isGameChosen() {
			return gameChosen;
		}

		public void setGameChosen(boolean gameChosen) {
			this.gameChosen = gameChosen;
		}

		//Player get/set
		public Player getPlayer() {
			return player;
		}

		public void setPlayer(Player player) {
				this.player = player;
		}

		//Original frame get/set (om te kunnen disposen achteraf)
		public JFrame getOriginalFrame() {
			return originalFrame;
		}
		
		//Methods
		/// <summary>
		/// Deze method zorgt ervoor dat de connectbutton kan enabled of disabled worden
		/// </summary>
		/// <author>Sebastian Kubski</author>
		public void enableConnect(boolean truth) {
			connect.setEnabled(truth);
		}		
		/// <summary>
		/// Deze method zorgt ervoor dat de tekst vd connectionLABEL op de gui kan aangepast worden door de client
		/// </summary>
		/// <author>Sebastian Kubski</author>
		public void veranderConnectStatus(String status) {
			connstatus.setText(status);
		}
		/// <summary>
		/// Deze method zet de originele frame op true/false parameter boolean
		/// </summary>
		/// <author>Sebastian Kubski</author>
		public void houdiniOriginalFrame(boolean truth) {
			originalFrame.setVisible(truth);
		}
}